package com.bwie.config;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import com.bwie.utils.R;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Title:
 * @BelongProjecet practice2
 * @BelongPackage com.bwie.config
 * @Description:
 * @Copyright 研发一部
 * @Author: Mr.yan
 * @Date: 2024/6/13 17:03
 * @Version V1.0
 */
@Configuration
public class SentinelException implements BlockExceptionHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, BlockException e) throws Exception {
        response.setContentType("application/json;charset=utf-8");
        response.setStatus(500);
        R r = R.error(500, "当前服务器繁忙请稍后重试");
        String respJson = JSON.toJSONString(r);
        response.getWriter().println(response);
    }
}
